import dom.xpath.query.ParseException;
import dom.xpath.query.xpath.XPContext;
import dom.xpath.query.xpath.XPathProcessor;
import dom.xpath.query.xpath.expr.*;
import dom.xpath.query.xpath.locpath.*;


public class Main {

	public static void main(String[] args) throws ParseException {
		//XPathProcessor xp = new XPathProcessor("/a/b/*[@x='1' and (@y='1' or @z='1')]");
		XPathProcessor xp = new XPathProcessor("/a/b/*[@x='1' and @y='1' and @z='0']");
		XPContext xpContext = xp.parse();
		
		Expression rootExpr = xpContext.getRoot();
		System.out.println(rootExpr);
		
		if (rootExpr instanceof AbsoluteLocationPath) {
			AbsoluteLocationPath pathExpr = (AbsoluteLocationPath) rootExpr;
			Steps steps = pathExpr.steps;
			Step  st = null;
			
			int n = steps.size();
			for (int i=0; i<n; ++i) {
				st = steps.get(i);
				System.out.print(st);
				System.out.println(" ... " + st.getClass());
				
				Test test = st.test;
				Preds preds = st.preds;
				
				System.out.println("TEST = \"" + test + "\"");
				System.out.println("PREDICATES");
				
				for (int p=0; p<preds.size(); p++) {
					Pred pred = preds.get(p);
					System.out.println("  " + pred);
					
					if (pred instanceof PredSimple) {
						PredSimple ps = (PredSimple)pred;
						Expression expr = ps.getExpr();
						System.out.print("  Expr type: ");

						if (expr instanceof And) {
							System.out.println("AND");
							And andExpr = (And)expr;
							for(int k = 0; k < andExpr.exprs.length; k++) {
								Expression e = andExpr.exprs[k];
								System.out.println("    " + e.getClass());
								System.out.println("    " + e + "\n");
								
								if (e instanceof Comparison) {
									Comparison compExpr = (Comparison)e;
									System.out.println("    Comparision:");
									System.out.println("    " + compExpr.expr1 + "(" + compExpr.expr1.getClass() + ")");
									System.out.println("    " + compExpr.type);
									System.out.println("    " + compExpr.expr2 + "(" + compExpr.expr2.getClass() + ")");
								}
								else {
									
								}
						    }
						}
						else if (expr instanceof Or) {
							System.out.println("OR");
							Or orExpr = (Or)expr;
							for(int k = 0; k < orExpr.exprs.length; k++) {
								Expression e = orExpr.exprs[k];
								System.out.println("    " + e.getClass());
								System.out.println("    " + e + "\n");
								
								if (e instanceof Comparison) {
									Comparison compExpr = (Comparison)e;
									System.out.println("    Comparision:");
									System.out.println("    " + compExpr.expr1 + "(" + compExpr.expr1.getClass() + ")");
									System.out.println("    " + compExpr.type);
									System.out.println("    " + compExpr.expr2 + "(" + compExpr.expr2.getClass() + ")");
								}
								else {
									
								}
						    }
						}
					}
				}
				System.out.println();
			}
		}
	}

}
